#include "main.hh"

int main() {
    MiniBank::BankingSystem bank;

    while (true) 
    {
        int choice = Get_Choice();

        switch (choice) 
        {
        case 1: 
        {
            Register(&bank);
            break;
        }
        case 2: 
        {
            AccessCustomerAccounts(bank);
            break;
        }
        case 3:
        {
            bank.displayAllAccounts();
            break;
        }
        case 4:
        {
            bank.generateGlobalTransactionReport();
            break;
        }
        case 5:
        {
            return 0;
        }
        }
    }
    return 0;
}

int Get_Choice()
{
    std::cout << "===== Banking System =====" << std::endl;
    std::cout << "1. Register new customer" << std::endl;
    std::cout << "2. Access customer accounts" << std::endl;
    std::cout << "3. Display all bank accounts" << std::endl;
    std::cout << "4. Transaction reports" << std::endl;
    std::cout << "5. Exit" << std::endl;
    int choice;
    while (true)
    {
        std::cout << "Please choose: ";
        std::cin >> choice;
        if (std::cin.fail())
        {
            std::cin.clear();
            std::cin.ignore(1000, '\n');
            std::cout << "Invalid input, please try again!\n";
            continue;
        }
        if (choice < 1 || choice >5)
        {
            std::cout << "Invalid Number, please try again!\n";
            continue;
        }

        break;
    }
    return choice;
}

void Register(MiniBank::BankingSystem* bank)
{
    std::string name;
    double initialBalance_saving;
    double initialBalance_checking;
    std::cout << "Enter customer name: ";
    std::cin.ignore(1000, '\n');
    std::getline(std::cin, name);
    std::cout << "Enter initial balance for Saving Account: ";
    std::cin >> initialBalance_saving;
    std::cin.ignore();
    std::cout << "Enter initial balance for Checking Account: ";
    std::cin >> initialBalance_checking;
    std::cin.ignore();
    (*bank).registerCustomer(name, initialBalance_saving, initialBalance_checking);
    std::cout << "Press Enter to continue...";
    std::cin.get();
}

void AccessCustomerAccounts(MiniBank::BankingSystem& bank)
{
    std::string name;
    std::cout << "Enter customer name: ";
    std::cin.ignore(1000, '\n');
    std::getline(std::cin, name);
    bank.accessCustomerAccounts(name);
}


